﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace scavenger.winforms
{
    public partial class HashCalculator : Form
    {
        public HashCalculator()
        {
            InitializeComponent();
        }

        private void cmdBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "All Files (*.*)|*.*";
            ofd.ShowDialog();
            if (ofd.FileName.Length > 0) 
            {
                txtFilename.Text = ofd.FileName;
            }
        }

        private void HashCalculator_Load(object sender, EventArgs e)
        {
            cmbHash.SelectedIndex = 0;
        }

        private void cmdCalcHash_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtFilename.Text))
            {
                MessageBox.Show("Invalid filename", Application.ProductName, MessageBoxButtons.OK);
                return;
            }
            Cursor = Cursors.WaitCursor;
            txtHash.Text = "";
            Application.DoEvents();
            txtHash.Text = Utils.GetHash(txtFilename.Text, (CryptoAlgoEnum)Enum.Parse(typeof(CryptoAlgoEnum), cmbHash.Text));
            Cursor = Cursors.Default;
        }

        private void txtFilename_Click(object sender, EventArgs e)
        {
            this.cmdBrowse_Click(null, null);
        }
    }
}
